package com.winz.cultureapp.adapter.xrcv;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.mine.xrecyclerview.rcvadapter.BaseRcvAdapter;
import com.mine.xrecyclerview.rcvadapter.ViewHolder;
import com.winz.cultureapp.R;
import com.winz.cultureapp.entity.ActivityListBean;
import com.winz.cultureapp.entity.HomeListBean;

import java.util.List;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * Created by terry on 2018/1/4.
 * 主界面
 */

public class ActivityDataAdapter extends BaseRcvAdapter<ActivityListBean.DataBean.ListBean> {
    private OnAddOrCancelListener listener;
    public ActivityDataAdapter(Context context, List<ActivityListBean.DataBean.ListBean> datas, int... resid) {
        super(context, datas, resid);
    }

    @Override
    public void convert(ViewHolder holder, ActivityListBean.DataBean.ListBean data, int itemViewType) {
        if (itemViewType != -1){
            holder.setText(R.id.tv_title,data.title)
                    .setText(R.id.tv_time,"日期：" + data.startTime +"至" + data.endTime)
                    .setText(R.id.tv_num,"余票" + (data.remainingVotes>999?"999+":data.remainingVotes)+"张")
                    .setText(R.id.tv_location,"地点：" + data.unitAddress);



            //圆角处理
            Glide.with(mContext)
                    .load(data.imageUrl)
                    .error(R.drawable.pic_default)
                    .into((ImageView) holder.getView(R.id.iv_pic));
        }
    }

    @Override
    public void convert(int position, ViewHolder holder, ActivityListBean.DataBean.ListBean listBean, int itemViewType) {
        super.convert(position, holder, listBean, itemViewType);
        if(itemViewType != -1){
            holder.setImageResource(R.id.iv_collection,listBean.collectionStatus == 1 ?R.drawable.icon_love_sel:R.drawable.icon_love_nor);
            holder.getView(R.id.iv_collection).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listener != null){
                        listener.onAddOrCancel(position);
                    }
                }
            });
        }
    }

    public interface OnAddOrCancelListener{
        void onAddOrCancel(int position);
    }

    public void setOnAddOrCancelListener(OnAddOrCancelListener listener){
        this.listener = listener;
    }
}
